IXR: check if scheme and host keys exist before accessing in IXR_Client and WP_HTTP_IXR_Client#10916
IXR: check if scheme and host keys exist before accessing in IXR_Client and WP_HTTP_IXR_Client#10916bluefuton wants to merge 4 commits intoWordPress:trunkfrom
Conversation
`parse_url()` does not always return a `host` key (e.g. for relative paths). Use the null coalescing operator to fall back to an empty string, consistent with how `port` and `path` are already handled. Adds a unit test to verify no error is triggered when the host is missing. Trac: https://core.trac.wordpress.org/ticket/64635
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
Should the same fix be applied to wordpress-develop/src/wp-includes/class-wp-http-ixr-client.php Lines 26 to 29 in d3b793f |
Yes, I think so. There's actually an open ticket already for this: https://core.trac.wordpress.org/ticket/40784 And the suggested patch was: https://core.trac.wordpress.org/attachment/ticket/40784/40784.diff Shall I address it in this PR @westonruter? |
|
@bluefuton ah, perfect. Yes, could you apply that patch to the PR and update it so we can address both together? |
5215b3c to
ec8d232
Compare
Co-authored-by: Weston Ruter <westonruter@gmail.com>
b4eabf1 to
2413b12
Compare
Added! 👍 I've modernized the original patch (using Sidenote It looks like at one point If we are now treating it as part of WP, we could probably do some further cleanup in there, like dropping PHP4 support. |
|
We should give @tfrommen props for the original patch on #40784 too :) |
|
@bluefuton It seems the only difference between the constructors for the two classes is that public function __construct( $server, $path = false, $port = false, $timeout = 15 ) {
parent::__construct( $server, $path, $port, $timeout );
$this->scheme = parse_url( $server, PHP_URL_SCHEME ) ?? 'http';
} |
Nice cleanup! There's one subtlety though - the parent |
Co-authored-by: Weston Ruter <westonruter@gmail.com>
|
Hey, nice to see some work on this. 😉 The above suggestion by @westonruter would always default to public function __construct( $server, $path = false, $port = false, $timeout = 15 ) {
parent::__construct( $server, $path, $port, $timeout );
$this->scheme = parse_url( $server, PHP_URL_SCHEME ) ?? 'http';
}However, the current code only does this (hard-coded) if there was no To keep that behavior, we would need to put the code inside a conditional. Also covering the different handling of the port, this would give us this: public function __construct( $server, $path = false, $port = false, $timeout = 15 ) {
parent::__construct( $server, $path, $port, $timeout );
if ( ! $path ) {
$this->scheme = parse_url( $server, PHP_URL_SCHEME ) ?? 'http';
$this->port = parse_url( $server, PHP_URL_PORT ) ?? '';
}
}Thoughts? |
|
I know we're a few years on from your original patch @tfrommen! Hope we can get it merged for you 🙂 The refactor to call |
|
@bluefuton Sounds good to me. @tfrommen How do you feel with the PR as it stands? If you approve, I'll proceed with commit. |
Summary
IXR_Clientaccesses$bits['host']fromparse_url()without checking if the key exists, which can trigger an undefined index warning for URLs without a host component (e.g. relative paths).??) to fall back to an empty string, consistent with howportandpathare already handled on the adjacent lines.Trac ticket
https://core.trac.wordpress.org/ticket/64635
https://core.trac.wordpress.org/ticket/40784
Test plan
IXR_Clientno longer triggers an undefined index warning when instantiated with a URL lacking a host componentnpm run test:php -- --filter ixr_clientand confirm the tests passDrafted Commit Message
XML-RPC: Account for parsed URLs that do not specify
hostorscheme.Developed in #10916
Props bluefuton, tfrommen, chrispecoraro, drebbits.web, westonruter.
Fixes #64635, #40784.